package com.chinaisafe.common.config;

import com.chinaisafe.common.config.converter.LocalDateConverter;
import com.chinaisafe.common.config.converter.LocalDateTimeConverter;
import com.chinaisafe.common.config.converter.LocalTimeConverter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * SpringWebMvcConfig
 * Description：SpringWebMvc相关配置
 *
 * @author JiangZhaoYong
 * @date 2024/7/10 19:22
 */
@Configuration
public class SpringWebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addFormatters(FormatterRegistry registry) {
        // 注册日期装换器
        registry.addConverter(new LocalDateConverter());
        // 注册日期时间装换器
        registry.addConverter(new LocalDateTimeConverter());
        // 注册时间装换器
        registry.addConverter(new LocalTimeConverter());
    }

    @Value("${springfox.documentation.swagger-ui.base-url:}")
    private String baseUrl;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(baseUrl + "/doc.html").addResourceLocations("classpath:/META-INF/resources/").resourceChain(false);
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
